package m.app.action.fun;

import m.app.action.AppAction;
import m.base.util.PowerUtil;
import m.common.action.ActionMeta;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.common.model.util.QueryOrder;
import m.fun.model.GoodsOffer;
import m.fun.model.OfferDetail;
import m.store.model.SaleInfo;
import m.store.model.StoreGoods;
import m.system.document.DocumentMeta;
import m.system.document.DocumentMethodMeta;
import m.system.document.DocumentParamMeta;
import m.system.util.JSONMessage;
import m.system.util.StringUtil;

@ActionMeta(name = "app/fun/goodsOffer",title = "app商品报价")
public class GoodsOfferAction extends AppAction {
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "商品报价查询列表",permission = true),
        params = {
            @DocumentParamMeta(name = "page.index",description = "分页开始位置",type = FieldType.INT),
            @DocumentParamMeta(name = "page.num",description = "分页每页数量",type = FieldType.INT),
            @DocumentParamMeta(name = "params[offerOid]",description = "报价单oid",type = FieldType.STRING,length = 50),
            @DocumentParamMeta(name = "params[oid@eq]",description = "条件示例，字段和操作符中间用@，值为空不添加",type = FieldType.STRING,length = 50),
            @DocumentParamMeta(name = "params[oid#desc]",description = "排序示例，字段和操作符中间用#，值为空不生效",type = FieldType.STRING,length = 50)
        }
    )
    public JSONMessage queryList() throws Exception {
        ModelQueryList queryList=toQueryList(GoodsOffer.class,"*","goods.*","goods.storeType.*");
        queryList.addCondition(QueryCondition.eq("user.oid",PowerUtil.getSessionUserOid()));
        queryList.addCondition(QueryCondition.not(
            QueryCondition.in("oid",
                ModelQueryList.instance(OfferDetail.class,new String[]{"goodsOffer.oid"},null,
                    QueryCondition.eq("offer.oid",getParamsValue("offerOid"))
                )
            )
        ));
        queryList.addOrder(
            QueryOrder.asc("goods.storeType.sort"),
            QueryOrder.asc("title")
        );
        return JSONMessage.success("查询成功")
                .push("page",ModelQueryList.getModelPageInfo(queryList));
    }
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "我的商品报价列表",permission = true),
        params = {
            @DocumentParamMeta(name = "page.index",description = "分页开始位置",type = FieldType.INT),
            @DocumentParamMeta(name = "page.num",description = "分页每页数量",type = FieldType.INT),
            @DocumentParamMeta(name = "params[oid@eq]",description = "条件示例，字段和操作符中间用@，值为空不添加",type = FieldType.STRING,length = 50),
            @DocumentParamMeta(name = "params[oid#desc]",description = "排序示例，字段和操作符中间用#，值为空不生效",type = FieldType.STRING,length = 50)
        }
    )
    public JSONMessage myList() throws Exception {
        verifyOfferFunc();
        ModelQueryList queryList=toQueryList(GoodsOffer.class,"*","goods.*","goods.storeType.*");
        queryList.addCondition(QueryCondition.eq("user.oid", PowerUtil.getSessionUserOid()));
        queryList.addOrder(
            QueryOrder.asc("goods.storeType.sort"),
            QueryOrder.asc("title")
        );
        return JSONMessage.success("查询成功").push("page",ModelQueryList.getModelPageInfo(queryList));
    }

}
